package net.lainiao.service.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.lainiao.base.model.ReptileTopic;
import net.lainiao.service.dao.ReptileFilterMapper;
import net.lainiao.service.dao.ReptileTopicMapper;
import net.lainiao.service.dao.ReptilemodelsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/1/7.
 */
@Service
public class ReptileTopicService {
    @Resource
    private ReptileTopicMapper reptileTopicMapper;
    @Resource
    private ReptileFilterMapper reptileFilterMapper;
    @Resource
    private ReptilemodelsMapper reptilemodelsMapper;

    public ReptileTopic getModelById(int id) {
        return reptileTopicMapper.selectByPrimaryKey(id);
    }

    public int saveModel(ReptileTopic model) {
        model.setStatus(0);
        if (model.getId()==null) {
            return reptileTopicMapper.insert(model);
        }
        else {
            return reptileTopicMapper.updateByPrimaryKey(model);
        }
    }

    public int delModel(int id){
        //删除过滤条件
        reptileFilterMapper.deleteByTid(id);
        //删除已经爬下来的链接
        reptilemodelsMapper.deleteByTid(id);
        return reptileTopicMapper.deleteByPrimaryKey(id);
    }

    public PageInfo<ReptileTopic> pageModes(int pageIndex,int pageSize){
        PageHelper.startPage(pageIndex,pageSize);
        List<ReptileTopic> list=reptileTopicMapper.selectAll();
        PageInfo<ReptileTopic> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    public List<ReptileTopic> getALL() {
        return reptileTopicMapper.selectAll();
    }


    public ReptileTopic getNoAccess() {
        return reptileTopicMapper.getNoAccess();
    }

    public void setAccess(Integer id) {
        reptileTopicMapper.setAccess(id);
    }
}
